﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataAccessLayer;

namespace BusinessLogicLayer
{
    public class ChangeCollectionControl
    {
        ChangeCollectionDAL ccDAL = new ChangeCollectionDAL();
        EmailNotificationControl emailControl = new EmailNotificationControl();

        public List<CollectionPoint> getCollectionPointsLst()
        {
            return ccDAL.getCollectionPointList();
        }

        public CollectionPointDetail getOneCollectionPoint(int id)
        {
            return ccDAL.getOneColPointDet(id);
        }

        public void saveNewCollectionPointDetail(int id, DateTime colDate, DateTime colTime, String userName)
        {
            List<Employee> emailList = ccDAL.saveNewCollectionPointDetail(id, colDate, colTime);

            String fromEmail = ccDAL.getEmailByUsername(userName);
            String toEmail;
            String Subject = "Collection Point changed";
            String Body;
            String recName;
            String colName = ccDAL.getColName(id);

            for (int i = 0; i < emailList.Count; i++)
            {
                recName = emailList[i].EmployeeName;
                toEmail = emailList[i].Email;

                Body = "Dear " + recName + ",\nThis is to inform you that the collection date " + colDate.ToShortDateString()
                    + " and collection time " + colTime.ToShortTimeString() + " for the collection point " + colName + " has been changed " + ".\n" +
                    "\nThank you!";

                emailControl.sendNotification(toEmail, fromEmail, Body, Subject);
            
            }
            
                        
        }

        public DateTime getFixCollectionTime(int id)
        {
            return ccDAL.getCollectionTime(id);
        }

        public CollectionPointDetail getOneCollectionPointDetail(int id)
        {
            return ccDAL.getOneColPointDet(id);  
        }
    }
}
